1   //==============================================================================
2   // file :       NewsSys.java
3   // project:     East Networks News System
4   //
5   // last change: date:       $Date: 2003/09/10 09:28:36 $
6   //              by:         $Author: bitiboy $
7   //              revision:   $Revision: 1.1 $
8   //------------------------------------------------------------------------------
9   // copyright:   GNU GPL Software License (see class documentation)
10  //==============================================================================
11  package net.eastol.news.jdo.bean;
12  
13  
14  /*
15   * $Id: NewsSys.java,v 1.1 2003/09/10 09:28:36 bitiboy Exp $
16   *
17   * Copyright 2003 Acai Software All Rights Reserved.
18   *
19   * This file NewsSys.java is part of the East Networks News System.
20  
21   * The East Networks News System is free software; you can redistribute it and/or modify
22   * it under the terms of the GNU General Public License as published by
23   * the Free Software Foundation; either version 2 of the License, or
24   * (at your option) any later version.
25  
26   * East Networks News System is distributed in the hope that it will be useful,
27   * but WITHOUT ANY WARRANTY; without even the implied warranty of
28   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29   * GNU General Public License for more details.
30  
31   * You should have received a copy of the GNU General Public License
32   * along with the East Networks News System; if not, write to the Free Software
33   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34  
35   * http://www.justhis.com http://ejb.cn
36   * CONTACT: email = webmaster@justhis.com superaxis@sohu.com
37   */
38  import com.justhis.util.Base64Utils;
39  import com.justhis.util.exception.UtilException;
40  
41  import java.util.ArrayList;
42  import java.util.Date;
43  
44  import javax.jdo.Extent;
45  import javax.jdo.JDOHelper;
46  import javax.jdo.PersistenceManager;
47  
48  
49  /***
50   * TODO DOCUMENT ME!
51   *
52   * @author <a href="http://blog.ejb.cn">acai</a>
53   * @version $Revision $
54   */
55  public class NewsSys implements JDOConst {
56      //~ Instance fields --------------------------------------------------------
57  
58      /*** TODO */
59      public ArrayList classList;
60  
61      /*** TODO */
62      public Date createdDate;
63  
64      //~ Constructors -----------------------------------------------------------
65  
66      /***
67       * Creates a new NewsSys object.
68       */
69      public NewsSys() {
70          super();
71  
72          
73      }
74  
75      //~ Methods ----------------------------------------------------------------
76  
77      /***
78       * TODO
79       *
80       * @return TODO
81       */
82      public ArrayList getClassList() {
83          return this.classList;
84      }
85  
86      /***
87       * @see net.eastol.news.jdo.bean.JDOConst#getObjectId()
88       */
89      public String getObjectId() throws UtilException {
90          Object oid = JDOHelper.getObjectId(this);
91          char[] m = null;
92  
93          m = Base64Utils.encode(oid);
94  
95          String oidStr = new String(m);
96  
97          return oidStr;
98      }
99  
100     /***
101      * TODO
102      *
103      * @param nc TODO
104      */
105     public void addClass(NewsClass nc) {
106         classList.add(nc);
107     }
108 
109     /***
110      * @see net.eastol.news.jdo.bean.JDOConst#delete()
111      */
112     public void delete() {
113         JDOHelper.getPersistenceManager(this).deletePersistent(this);
114     }
115 
116     /***
117      * @param nc
118      */
119     public void deleteClass(NewsClass nc) throws UtilException {
120         deleteClass(classList, nc);
121     }
122 
123     /***
124      * TODO
125      *
126      * @return TODO
127      */
128     public NewsSys init() {
129         classList = new ArrayList();
130         createdDate = new Date();
131 
132         return this;
133     }
134 
135     /***
136      * TODO
137      *
138      * @param pm TODO
139      *
140      * @return TODO
141      *
142      * @throws UtilException TODO
143      */
144     public static String initSystem(PersistenceManager pm)
145                              throws UtilException {
146         String oid = "";
147 
148         pm.currentTransaction().begin();
149 
150         Extent ext = pm.getExtent(NewsSys.class, false);
151         boolean created = false;
152         created = (ext.iterator()).hasNext();
153 
154         if (created) {
155             oid = ((JDOConst) ext.iterator().next()).getObjectId();
156         }
157 
158         ext.closeAll();
159 
160         if (created) {
161             pm.currentTransaction().rollback();
162         } else {
163             NewsSys ns = new NewsSys();
164             ns.init();
165             pm.makePersistent(ns);
166             pm.currentTransaction().commit();
167             oid = ns.getObjectId();
168         }
169 
170         return oid;
171     }
172 
173     /***
174      * TODO
175      *
176      * @param childList TODO
177      * @param child TODO
178      */
179     private void deleteClass(ArrayList childList, NewsClass child) {
180         if (childList.size() == 0) {
181             return;
182         } else {
183             if (childList.remove(child)) {
184                 child.delete();
185 
186                 return;
187             } else {
188                 for (int i = 0; i < childList.size(); i++) {
189                     deleteClass(((NewsClass) childList.get(i)).getChildList(),
190                                 child
191                                );
192                 }
193             }
194         }
195     }
196 }
197 
198 
199 /*
200  * $Log: NewsSys.java,v $
201  * Revision 1.1  2003/09/10 09:28:36  bitiboy
202  * *** empty log message ***
203  *
204  *
205 */
This page was automatically generated by Maven